package com.cy.pj.notice.web.pojo;

/**
 * 响应数据规范：要返回什么数据，以什么格式进行响应
 * 基于JsonResult对象封装服务端响应到客户端数据
 * 通常包含三部分：
 * 状态码、信息、数据
 */
public class JsonResult {   // 服务端响应到客户端的数据标准对象
    private Integer state = 1; // 1标识Ok，0标识Exception
    private String message;
    private Object data;

    public JsonResult(Object data) {
        this.data = data;
    }

    public JsonResult(String message) {
        this.message = message;
    }

    public JsonResult(String message, Object data) {
        this.message = message;
        this.data = data;
    }

    public JsonResult(Integer state, String message) {
        this.state = state;
        this.message = message;
    }

    public JsonResult(Throwable e){
//        this.state=0;
//        this.message=e.getMessage();
        this(0,e.getMessage());
    }

    public Integer getState() {
        return state;
    }

    public void setState(Integer state) {
        this.state = state;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    @Override
    public String toString() {
        return "JosnResult{" +
                "state=" + state +
                ", message='" + message + '\'' +
                ", data=" + data +
                '}';
    }
}
